
// import _update from "./utils/_update";

import _openid from "./cache/_openid";
import _layer from "./common/_layer";
import lib_tiktok from "./api/lib_tiktok";

// app.js
App({
    single_globalData: {
        citys: [],
        msrp_max: 0,
        msrp_min: 0,
        guiding_price: 0,
    },
    onLaunch(data) {
        tt.clearStorage({
            success: (res) => {
                this.Login()
            },
            fail: (res) => {
                _layer.message('请手动清除缓存')
            },
        });
        
    },
    Login() {
        tt.login({
            success: res => {
                if (res.errMsg = "login:ok") {
                    // console.log(res.code, 'code');
                    lib_tiktok.openid(res.code).then(response => {
                        if (response.code == 0) {
                            //缓存openid
                            _openid.set(response.data.openid)
                        } else {
                            _layer.message(response.msg)
                        }
                    })
                } else {
                    console.log('未识别到用户身份，请授权');
                    // _layer.message('未识别到用户身份，请授权')
                }
            },
            fail: err => {
                console.log(err);

            },
            complete: cpl => {
                // console.log(cpl);
            }
        })
    },

});